﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WjAutoConfigApp
{
    public partial class TestForm : Form
    {
        private ArrayList pArray = new ArrayList();
        private Pen pen1 = new Pen(Color.Red);
        bool isFinished = false;
        public TestForm()
        {
            InitializeComponent();
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = this.CreateGraphics();

            int i;
            for (i = 0; i < pArray.Count - 1; i++)
                g.DrawLine(pen1, (Point)pArray[i], (Point)pArray[i + 1]);
            if (pArray.Count >= 3 && isFinished)
                g.DrawLine(pen1, (Point)pArray[i], (Point)pArray[0]);
            base.OnPaint(e);

        }

        private void TestForm_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left && !isFinished)
            {
                pArray.Add(new Point(e.X, e.Y));
                this.Invalidate();

            }
            if (e.Button == MouseButtons.Right)
            {
                isFinished = true;
                this.Invalidate();
            }
        }
    }
}
